package jsi.service;

import java.sql.SQLException;
import java.util.List;

import jsi.service.dao.PersonDAO;

import org.hibernate.HibernateException;
import org.hibernate.SQLQuery;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.transaction.annotation.Transactional;

@Transactional
public class PersonServiceImpl extends HibernateDaoSupport implements PersonService{

	PersonDAO personDao;
	
	public Integer countPersons() {
		return (Integer) getHibernateTemplate().execute(new HibernateCallback(){

			public Object doInHibernate(Session session)
					throws HibernateException, SQLException {
				SQLQuery query = session.createSQLQuery("select count(1) from Person");
				Integer count = (Integer)query.list().get(0);
				return count;
			}
			
		});
	}
	
	public void setPersonDao(PersonDAO personDao) {
		this.personDao = personDao;
	}

}
